package com.example.controller;

import com.example.entity.GoodsCategory;
import com.example.service.GoodsCategoryService;
import com.example.vo.Result;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController()
@Slf4j
@RequestMapping()
public class GoodsCategoryController {
    @Resource()
    private GoodsCategoryService goodsCategoryService;

    @Operation(summary = "获取首页分类列表")
    @GetMapping("/buyer/common/getCategoryList")
    public Result<List<GoodsCategory>> getGoodsCategoryList(){
        List<GoodsCategory> categoryList = goodsCategoryService.getGoodsCategoryList();
        return Result.ok(categoryList);
    }

    @PostMapping("/category/add")
    public Result<Boolean> addChildrenCategory(@RequestBody GoodsCategory child){
        int re = goodsCategoryService.addChildrenCategory(child);
        return Result.ok(re>0);
    }

    @PostMapping("/category/ban")
    public Result<Boolean> ban(@RequestParam("categoryId") Long categoryId){
        int re = goodsCategoryService.updateStatus(false,categoryId);
        return Result.ok(re>0);
    }

    @PostMapping("/category/open")
    public Result<Boolean> open(@RequestParam("categoryId") Long categoryId){
        int re = goodsCategoryService.updateStatus(true,categoryId);
        return Result.ok(re>0);
    }

    @PostMapping("/category/edit")
    public Result<Boolean> edit(@RequestBody GoodsCategory goodsCategory){
        int re = goodsCategoryService.editCategory(goodsCategory);
        return Result.ok(re>0);
    }


}